﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
using System.Text;
using System.Collections;
using GreatB2C.Utility;

namespace GreatB2C.Web.Controls
{
    public partial class TemplateSelect : System.Web.UI.UserControl
    {
        /// <summary>
        /// 获取模板路径
        /// </summary>
        public string TemplatePath
        {
            get
            {
                return txtTemplateName.Text.Trim( );
            }
        }

        protected void Page_Load( object sender , EventArgs e )
        {            
            if ( !IsPostBack )
            {
                litScript.Text = "<script type=\"text/javascript\">" + Utility.DataDefine.NewLine
                    + "    function " + this.ClientID + "_UploadImage() {" + Utility.DataDefine.NewLine
                    + "        var top = (document.documentElement.clientHeight - 400) / 2;" + Utility.DataDefine.NewLine
                    + "        var left = (document.documentElement.clientWidth - 500) / 2;" + Utility.DataDefine.NewLine
                    + "        " + Utility.DataDefine.NewLine
                    + "        $(\"#" + this.ClientID + "_divDirectory\").html(\"<ul id='" + this.ClientID + "_dir'></ul>\");" + Utility.DataDefine.NewLine
                    + "" + Utility.DataDefine.NewLine
                    + "        $.ajax({" + Utility.DataDefine.NewLine
                    + "            url: \"/Json/Common/Common.aspx?action=templatelist&ctl=" + this.ClientID + "\"," + Utility.DataDefine.NewLine
                    + "            type: 'GET'," + Utility.DataDefine.NewLine
                    + "            cache: false," + Utility.DataDefine.NewLine
                    + "            success: function(htmlstr) {" + Utility.DataDefine.NewLine
                    //+ "                //debugger;" + Utility.DataDefine.NewLine
                    + "                if (htmlstr != \"\") {" + Utility.DataDefine.NewLine
                    + "                    $(\"#" + this.ClientID + "_dir\").html(htmlstr);" + Utility.DataDefine.NewLine
                    + "                    $(\"#" + this.ClientID + "_dir\").tree();" + Utility.DataDefine.NewLine
                    + "                }" + Utility.DataDefine.NewLine
                    + "            }" + Utility.DataDefine.NewLine
                    + "        });" + Utility.DataDefine.NewLine
                    + "" + Utility.DataDefine.NewLine
                    + "        " + this.ClientID + "_loadfile('商城模板方案');" + Utility.DataDefine.NewLine
                    + "" + Utility.DataDefine.NewLine
                    + "        $('#" + this.ClientID + "_win').window({" + Utility.DataDefine.NewLine
                    + "            title: '模板选择'," + Utility.DataDefine.NewLine
                    + "            width: 670," + Utility.DataDefine.NewLine
                    + "            height: 450," + Utility.DataDefine.NewLine
                    + "            modal: true," + Utility.DataDefine.NewLine
                    + "            shadow: true," + Utility.DataDefine.NewLine
                    + "            closed: false," + Utility.DataDefine.NewLine
                    + "            resizable: false," + Utility.DataDefine.NewLine
                    + "            minimizable: false," + Utility.DataDefine.NewLine
                    + "            maximizable: false," + Utility.DataDefine.NewLine
                    + "            top: top," + Utility.DataDefine.NewLine
                    + "            left: left" + Utility.DataDefine.NewLine
                    + "        });" + Utility.DataDefine.NewLine
                    + "    }" + Utility.DataDefine.NewLine
                    + "" + Utility.DataDefine.NewLine
                    + "    function " + this.ClientID + "_loadfile(path) {" + Utility.DataDefine.NewLine
                    + "        $.ajax({" + Utility.DataDefine.NewLine
                    + "            url: \"/Json/Common/Common.aspx?action=filelist&ctl=" + this.ClientID + "&path=/\" + encodeURIComponent(path)," + Utility.DataDefine.NewLine
                    + "            type: 'GET'," + Utility.DataDefine.NewLine
                    + "            cache: false," + Utility.DataDefine.NewLine
                    + "            success: function(htmlstr) {" + Utility.DataDefine.NewLine
                    + "                //debugger;" + Utility.DataDefine.NewLine
                    + "                if (htmlstr != \"\") {" + Utility.DataDefine.NewLine
                    + "                    $(\"#" + this.ClientID + "_filelist\").html(htmlstr);" + Utility.DataDefine.NewLine
                    + "                }" + Utility.DataDefine.NewLine
                    + "            }" + Utility.DataDefine.NewLine
                    + "        });" + Utility.DataDefine.NewLine
                    + "    }" + Utility.DataDefine.NewLine
                    + "" + Utility.DataDefine.NewLine
                    + "    function " + this.ClientID + "_choose(path) {" + Utility.DataDefine.NewLine
                    + "        $(\"#" + txtTemplate.ClientID + "\").val(path);" + Utility.DataDefine.NewLine
                    + "    }" + Utility.DataDefine.NewLine
                    + "" + Utility.DataDefine.NewLine
                    + "    function " + this.ClientID + "_closeWin() {" + Utility.DataDefine.NewLine
                    + "        $('#" + this.ClientID + "_win').window('close');" + Utility.DataDefine.NewLine
                    + "    }" + Utility.DataDefine.NewLine
                    + "" + Utility.DataDefine.NewLine
                    + "    function " + this.ClientID + "_submitchoose() {" + Utility.DataDefine.NewLine
                    + "        $(\"#" + txtTemplateName.ClientID + "\").val($(\"#" + txtTemplate.ClientID + "\").val());" + Utility.DataDefine.NewLine
                    + "        " + this.ClientID + "_closeWin();" + Utility.DataDefine.NewLine
                    + "    }" + Utility.DataDefine.NewLine
                    + "    function " + this.ClientID + "_choosed(path) {" + Utility.DataDefine.NewLine
                    + "        $(\"#" + txtTemplateName.ClientID + "\").val(path);" + Utility.DataDefine.NewLine
                    + "        " + this.ClientID + "_closeWin();" + Utility.DataDefine.NewLine
                    + "    }" + Utility.DataDefine.NewLine
                    + "</script>" + Utility.DataDefine.NewLine;

                btnBrowser.Attributes.Add( "onclick" , this.ClientID + "_UploadImage();" );
            }
        }
    }
}